package com.bfxy.rabbitmq.api.delay;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * create by zhangtian3 on 2019/3/28
 */
public class Procuder {
    public static void main(String[] args) throws Exception {
        ConnectionFactory connectionFactory = new ConnectionFactory() ;
        connectionFactory.setHost("106.12.109.239");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("123456");
        connectionFactory.setVirtualHost("/hadoop");

        Connection connection = connectionFactory.newConnection() ;
        Channel channel = connection.createChannel() ;

        String exchangeName = "test-delay-exchange-new" ;
        String routingKey = "delaynew.save" ;

        // 声明x-delayed-type类型的exchange
        Map<String, Object> agruments = new HashMap<String, Object>();
        agruments.put("x-delay", 30000);

        AMQP.BasicProperties.Builder props = new AMQP.BasicProperties.Builder().headers(agruments);

        String msg = "Hello RabbitMQ Delay Message" ;
        for (int i = 0; i < 2 ; i++) {
            channel.basicPublish(exchangeName, routingKey, props.build(), msg.getBytes());
        }
    }
}
